<?php
/**
 * 基础配置
 */

namespace app\badmin\controller;


use app\badmin\model\Company as CompanyModel;
use app\badmin\model\CompanyAgent as CompanyAgentModel;
use app\common\controller\BadminController;
use think\Exception;
use think\facade\Request;

class Config extends BadminController {


    /**
     * 默认客服获取
     * @return false|string
     */
    public function kefuConfigGet() {
        try {
            $params = $this->checkParams('');
            if ($params === false) return $this->resErr();
            $res = CompanyAgentModel::getKefu($params);
            if (!$res) return $this->resErr();
            $list = CompanyAgentModel::agentList($params);
            return $this->resData('success', compact('res', 'list'));
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 默认客服提交
     * @return false|string
     */
    public function kefuConfigPost() {
        try {
            $params = $this->checkParams('id');
            if ($params === false) return $this->resErr();
            $res = CompanyAgentModel::setKefu($params);
            if (!$res) return $this->resErr();
            else return $this->resData('设置成功', []);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 公司信息
     * @return false|string
     */
    public function getCompanyInfo() {
        try {
            $params = $this->checkParams('');
            if ($params === false) return $this->resErr();
            $res = CompanyModel::getInfo($params);
            return $this->resData('succcess', $res);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 编辑
     * @return false|string
     */
    public function editCompanyPost() {
        try {
            $params = $this->checkParams('video,video_cover');
            $res = CompanyModel::edit($params);
            if (!$res) return $this->resErr();
            else return $this->resData('修改成功', []);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

}